using System.Data;
using System.Data.SqlClient;
using System.Web.UI.WebControls;
using AdCom.Utility;

namespace VDC.VONE.DAL
{

    #region About
    /// <summary>
	/// Class DonviData
    /// Create by: HungND
    /// Description: DAL Nguoi dung
    /// 05/03/2013 
	/// </summary>
	#endregion

	public class DonviData
	{
		#region Contructor
		public DonviData()
		{
			//
			// TODO: Add constructor logic here
			//
		}
		#endregion
		//--------------------------------
		#region GetDonvi

		public DataTable GetDonvi()
		{
			DataTable dt = SqlDataHelper.CallRetrievalStoredProcedure("MIS_don_vi_GET",
				new SqlParameter[]{
					new SqlParameter("@id_don_vi",System.DBNull.Value),
					new SqlParameter("@ma_don_vi",System.DBNull.Value),
					new SqlParameter("@ten_don_vi",System.DBNull.Value),
					new SqlParameter("@don_vi_cha",System.DBNull.Value),
					new SqlParameter("@ghi_chu",System.DBNull.Value),
                    new SqlParameter("@loai",System.DBNull.Value),
                    new SqlParameter("@sap_xep",System.DBNull.Value),
                    new SqlParameter("@nhom",System.DBNull.Value)
					});
			return dt;
		}
        public DataTable GetDonvi_By_Donvicha(int don_vi_cha)
        {
            DataTable dt = SqlDataHelper.CallRetrievalStoredProcedure("MIS_don_vi_GET",
                new SqlParameter[]{
					new SqlParameter("@id_don_vi",System.DBNull.Value),
					new SqlParameter("@ma_don_vi",System.DBNull.Value),
					new SqlParameter("@ten_don_vi",System.DBNull.Value),
					new SqlParameter("@don_vi_cha",don_vi_cha),
					new SqlParameter("@ghi_chu",System.DBNull.Value),
                    new SqlParameter("@loai",System.DBNull.Value),
                    new SqlParameter("@sap_xep",System.DBNull.Value),
                    new SqlParameter("@nhom",System.DBNull.Value)
					});
            return dt;
        }
        public DataTable GetDonviByMaDonVi(string ma_don_vi)
        {
            DataTable dt = SqlDataHelper.CallRetrievalStoredProcedure("MIS_don_vi_GET",
                new SqlParameter[]{
					new SqlParameter("@id_don_vi",System.DBNull.Value),
					new SqlParameter("@ma_don_vi",ma_don_vi),
					new SqlParameter("@ten_don_vi",System.DBNull.Value),
					new SqlParameter("@don_vi_cha",System.DBNull.Value),
					new SqlParameter("@ghi_chu",System.DBNull.Value),
                    new SqlParameter("@loai",System.DBNull.Value),
                    new SqlParameter("@sap_xep",System.DBNull.Value),
                    new SqlParameter("@nhom",System.DBNull.Value)
					});
            return dt;
        }
        //--------------------------------
        public DataTable GetDonvi(int id_don_vi, string ma_don_vi, string ten_don_vi, int don_vi_cha, string ghi_chu, string loai)
        {
            DataTable dt = SqlDataHelper.CallRetrievalStoredProcedure("MIS_don_vi_GET_Donvinhan",
                new SqlParameter[]{
					new SqlParameter("@id_don_vi",id_don_vi),
					new SqlParameter("@ma_don_vi",ma_don_vi),
					new SqlParameter("@ten_don_vi",ten_don_vi),
					new SqlParameter("@don_vi_cha",don_vi_cha),
					new SqlParameter("@ghi_chu",ghi_chu),
                    new SqlParameter("@loai",loai),
                    new SqlParameter("@sap_xep",System.DBNull.Value),
                    new SqlParameter("@nhom",System.DBNull.Value)
					});
            return dt;
        }
        public DataTable GetDonvi(int id_don_vi, string ma_don_vi, string ten_don_vi, int don_vi_cha, string ghi_chu, string loai, int nhom)
        {
            DataTable dt = SqlDataHelper.CallRetrievalStoredProcedure("MIS_don_vi_GET",
                new SqlParameter[]{
					new SqlParameter("@id_don_vi",id_don_vi),
					new SqlParameter("@ma_don_vi",ma_don_vi),
					new SqlParameter("@ten_don_vi",ten_don_vi),
					new SqlParameter("@don_vi_cha",don_vi_cha),
					new SqlParameter("@ghi_chu",ghi_chu),
                    new SqlParameter("@loai",loai),
                    new SqlParameter("@sap_xep",System.DBNull.Value),
                    new SqlParameter("@nhom",nhom)
					});
            return dt;
        }
        //--------------------------------
        /// <summary>
        ///     Get DataSet All Dauviec by id_cong_van
        ///     By HUNGND
        ///     Date: 18-06-2008 : 15.11
        /// </summary>
        /// <param name="id_cong_van"></param>
        /// <returns></returns>
        public DataSet GetDateSetTrangThaiDauviecDonViBy(int id_cong_van)
        {
            DataSet dt = SqlDataHelper.CallRetrievalStoredProcedureDataSet("MIS_don_vi_GetALLTrangThaiDauviecDonViBy",
                new SqlParameter[]{
                    new SqlParameter("@id_cong_van",id_cong_van)
                    });
            return dt;
        }
        //
		//--------------------------------
        public DataTable GetAllDonviByID_dauviecAndID_congvan(int p_id_dau_viec, int p_id_cong_van)
        {
            DataTable dt = SqlDataHelper.CallRetrievalStoredProcedure("MIS_don_vi_GET_ByID_dauviec_andID_congvan",
                new SqlParameter[]{
					new SqlParameter("@id_dau_viec",p_id_dau_viec),
                    new SqlParameter("@id_cong_van",p_id_cong_van)
					});
            return dt;
        }
        //Lay tat ca cac don vi va trang thai xu ly cua don vi nhan dau viec
        public DataTable GETALL_xulydauviecBy(int p_id_dau_viec, int p_id_cong_van)
        {
            DataTable dt = SqlDataHelper.CallRetrievalStoredProcedure("MIS_don_vi_GETALL_xulydauviecBy",
                new SqlParameter[]{
					new SqlParameter("@id_dau_viec",p_id_dau_viec),
                    new SqlParameter("@id_cong_van",p_id_cong_van)
					});
            return dt;
        }
        //--------------------------------
		public DataTable GetDonviByID(int id_don_vi)
		{
			DataTable dt = SqlDataHelper.CallRetrievalStoredProcedure("MIS_don_vi_GET",
				new SqlParameter[]{
					new SqlParameter("@id_don_vi",id_don_vi),
					new SqlParameter("@ma_don_vi",System.DBNull.Value),
					new SqlParameter("@ten_don_vi",System.DBNull.Value),
					new SqlParameter("@don_vi_cha",System.DBNull.Value),
					new SqlParameter("@ghi_chu",System.DBNull.Value),
                    new SqlParameter("@loai",System.DBNull.Value),
                    new SqlParameter("@sap_xep",System.DBNull.Value),
                    new SqlParameter("@nhom",System.DBNull.Value)
					});
			return dt;
		}
        public DataTable GetAllDonviBy_id_cong_van(int id_cong_van)
        {
            DataTable dt = SqlDataHelper.CallRetrievalStoredProcedure("MIS_don_vi_GETALL_By_id_cong_van",
                new SqlParameter[]{
					new SqlParameter("@id_cong_van",id_cong_van)
					});
            return dt;
        }
        //Get don vi by ten_dang_nhap
        public DataTable GetDonviByUser(string ten_dang_nhap)
        {
            DataTable dt = SqlDataHelper.CallRetrievalStoredProcedure("MIS_don_vi_GET_BY_USER",
                new SqlParameter[]{
					//new SqlParameter("@ma_don_vi",System.DBNull.Value),
                    //new SqlParameter("@ten_don_vi",System.DBNull.Value),
                    new SqlParameter("@ten_dang_nhap",ten_dang_nhap)
					});
            return dt;
        }

        public DataTable GetAllDonviBy_id_dau_viec(int id_dau_viec)
        {
            DataTable dt = SqlDataHelper.CallRetrievalStoredProcedure("MIS_don_vi_GET_By_id_dau_viec",
                new SqlParameter[]{
					new SqlParameter("@id_dau_viec",id_dau_viec)
					});
            return dt;
        }
		//--------------------------------
		public void BindData(ref SqlDataSource sqlData,string ma_don_vi, string ten_don_vi, int don_vi_cha, string ghi_chu)
		{
			AdSqlDataSource.CallSelectStore(ref sqlData, "MIS_don_vi_GET",
				new SqlParameter[]{
					new SqlParameter("id_don_vi",System.DBNull.Value),
					new SqlParameter("ma_don_vi",ma_don_vi),
					new SqlParameter("ten_don_vi",ten_don_vi),
					new SqlParameter("don_vi_cha",don_vi_cha),
					new SqlParameter("ghi_chu",ghi_chu)
					});
		}
        //--------------------------------
        public void BindData_ByIDCongvan(ref SqlDataSource sqlData, int id_cong_van)
        {
            AdSqlDataSource.CallSelectStore(ref sqlData, "MIS_don_vi_GETALL_By_id_cong_van",
                new SqlParameter[]{
					new SqlParameter("id_cong_van",id_cong_van)
					});
        }
		//--------------------------------
		#endregion
		//--------------------------------
		#region InsertDonvi
        public int InsertDonvi(string ma_don_vi, string ten_don_vi, int don_vi_cha, string ghi_chu, string loai, int sap_xep, int nhom, int sap_xep_bctuan)
		{
			int i = (int)SqlDataHelper.CallActionStoredProcedure("MIS_don_vi_SET",
					new SqlParameter[]{
						new SqlParameter("@id_don_vi",System.DBNull.Value),
						new SqlParameter("@ma_don_vi",ma_don_vi),
						new SqlParameter("@ten_don_vi",ten_don_vi),
						new SqlParameter("@don_vi_cha",don_vi_cha),
						new SqlParameter("@ghi_chu",ghi_chu),
                        new SqlParameter("@loai",loai),
                        new SqlParameter("@sap_xep",sap_xep),
                        new SqlParameter("@nhom",nhom),
                        new SqlParameter("@sap_xep_bctuan",sap_xep_bctuan),
						new SqlParameter("@AdComUserName",System.Web.HttpContext.Current.User.Identity.Name)
						});
			return i;
		}
		#endregion
		//--------------------------------
		#region UpdateDonvi
        public int UpdateDonvi(int id_don_vi, string ma_don_vi, string ten_don_vi, int don_vi_cha, string ghi_chu, string loai, int sap_xep, int nhom, int sap_xep_bctuan)
		{
			int i = (int)SqlDataHelper.CallActionStoredProcedure("MIS_don_vi_SET",
					new SqlParameter[]{
						new SqlParameter("@id_don_vi",id_don_vi),
						new SqlParameter("@ma_don_vi",ma_don_vi),
						new SqlParameter("@ten_don_vi",ten_don_vi),
						new SqlParameter("@don_vi_cha",don_vi_cha),
						new SqlParameter("@ghi_chu",ghi_chu),
                        new SqlParameter("@loai",loai),
                        new SqlParameter("@sap_xep",sap_xep),
                        new SqlParameter("@nhom",nhom),
                        new SqlParameter("@sap_xep_bctuan",sap_xep_bctuan),
						new SqlParameter("@AdComUserName",System.Web.HttpContext.Current.User.Identity.Name)
						});
			return i;
		}
		#endregion
		//--------------------------------
		#region DeleteDonvi
		/// <summary>
		///     Thu tuc xoa bang khoa chinh
		/// </summary>
		public void DeleteDonviByID(ref SqlDataSource sqd, int id_don_vi)
		{
			AdSqlDataSource.CallDeleteStore(ref sqd, "MIS_don_vi_DELETE",
				new SqlParameter[]{
					new SqlParameter("id_don_vi",id_don_vi),
					new SqlParameter("AdComUserName",System.Web.HttpContext.Current.User.Identity.Name)
				});
			sqd.Delete();
		}
		//------------------------------------//
		public void DeleteDonviByID(int id_don_vi)
		{
			new AdSqlDataLocalHelper().CallActionStoredProcedure("MIS_don_vi_DELETE",
				new SqlParameter[]{
					new SqlParameter("id_don_vi",id_don_vi),
					new SqlParameter("AdComUserName",System.Web.HttpContext.Current.User.Identity.Name)
				});
		}
		//------------------------------------//
		public void DeleteDonviByIDFKey(int don_vi_cha)
		{
			new AdSqlDataLocalHelper().CallActionStoredProcedure("MIS_don_vi_DELETE",
				new SqlParameter[]{
					new SqlParameter("id_don_vi",System.DBNull.Value),
					new SqlParameter("don_vi_cha",don_vi_cha),
					new SqlParameter("AdComUserName",System.Web.HttpContext.Current.User.Identity.Name)
				});
		}
		//--------------------------------
		/// <summary>
		///     Thu tuc xoa nhieu item do nguoi dung lua chon
		/// </summary>
		public void DeleteDonviAll(ref SqlDataSource sqd, string strID)
		{
			AdSqlDataSource.CallDeleteStore(ref sqd, "MIS_don_vi_DELETEAll",
				new SqlParameter[]{
					new SqlParameter("strid_don_vi",strID),
					new SqlParameter("AdComUserName",System.Web.HttpContext.Current.User.Identity.Name)
				});
			sqd.Delete();
		}
		public void DeleteDonviAllFKey(string don_vi_cha)
		{
			new AdSqlDataLocalHelper().CallActionStoredProcedure("MIS_don_vi_DELETEAll",
				new SqlParameter[]{
					new SqlParameter("strid_don_vi",System.DBNull.Value),
					new SqlParameter("strdon_vi_cha",don_vi_cha),
					new SqlParameter("AdComUserName",System.Web.HttpContext.Current.User.Identity.Name)
				});
		}

		#region command
		public string GetStringID(string strdon_vi_cha,int id)
		{
			AdCom.Utility.AdSqlDataLocalHelper ash = new AdSqlDataLocalHelper();
			return ash.SelectScalarString(strdon_vi_cha, "don_vi","id_don_vi=" + AdCom.Utility.SqlDataHelper.EscapeQuote(id.ToString()));
		}
		#endregion
		#endregion
        #region Get All Don Vi(LNHAI)
        public void BindGridView(ref SqlDataSource sqlData, string ma_don_vi, string ten_don_vi, int don_vi_cha)
        {
            AdSqlDataSource.CallSelectStore(ref sqlData, "MIS_don_vi_Get_donvingoai",
                new SqlParameter[]{
					new SqlParameter("id_don_vi",System.DBNull.Value),
					new SqlParameter("ma_don_vi",ma_don_vi),
					new SqlParameter("ten_don_vi",ten_don_vi),
					new SqlParameter("don_vi_cha",don_vi_cha),
					new SqlParameter("ghi_chu",System.DBNull.Value)
					});
        }
        //public DataTable Get_All_Donvi_by_id_donvi(int id_don_vi)
        //{
        //    DataTable dt = SqlDataHelper.CallRetrievalStoredProcedure("MIS_don_vi_Get_Tree_Don_Vi",
        //        new SqlParameter[]{
        //            new SqlParameter("@id_don_vi",id_don_vi)			
        //            });
        //    return dt;
        //}

        public DataTable CheckDeleteDonviphong(int id_don_vi)
        {
            DataTable dt = SqlDataHelper.CallRetrievalStoredProcedure("MIS_don_vi_Get_All_Donvi_by_id_donvi",
                new SqlParameter[]{
					new SqlParameter("@id_don_vi",id_don_vi)			
					});
            return dt;
        }

        public DataTable Get_donvi_by_loai(int loai)
        {
            DataTable dt = SqlDataHelper.CallRetrievalStoredProcedure("MIS_don_vi_Get_donvi_loai",
                new SqlParameter[]{
					new SqlParameter("@loai",loai)				
					});
            return dt;
        }
        public DataTable Get_donvi_by_loai_2(int loai, int id_donvi_hientai)
        {
            //tham so id_donvi_hientai dung de loai bo don vi hien tai khoi danh sach don vi
            DataTable dt = SqlDataHelper.CallRetrievalStoredProcedure("MIS_don_vi_Get_donvi_loai_2",
                new SqlParameter[]{
					new SqlParameter("@loai",loai),
                    new SqlParameter("@id_donvi_hientai",id_donvi_hientai)
					});
            return dt;
        }
        public DataTable Get_all_donvi_dbnb()
        {
            DataTable dt = SqlDataHelper.CallRetrievalStoredProcedure("MIS_danhba_noibo_Get_donvi",
                new SqlParameter[]{
					new SqlParameter("@id_don_vi",System.DBNull.Value)				
					});
            return dt;
        }

        public DataTable Get_donvi_tapdoan()
        {
            DataTable dt = SqlDataHelper.CallRetrievalStoredProcedure("MIS_danhba_noibo_Get_donvi_tapdoan",
                new SqlParameter[]{
					new SqlParameter("@id_don_vi",System.DBNull.Value)				
					});
            return dt;
        }

        public DataTable Get_donvi_bo()
        {
            DataTable dt = SqlDataHelper.CallRetrievalStoredProcedure("MIS_danhba_noibo_Get_donvi_bo",
                new SqlParameter[]{
					new SqlParameter("@id_don_vi",System.DBNull.Value)				
					});
            return dt;
        }
    
        public DataTable Get_All_donviphong(int id_don_vi, int nhom)
        {
            DataTable dt = SqlDataHelper.CallRetrievalStoredProcedure("MIS_don_vi_Get_donviphong",
                new SqlParameter[]{
					new SqlParameter("@id_don_vi",id_don_vi),
				    new SqlParameter("@nhom",nhom)
					});
            return dt;
        }

        public DataTable Get_All_donvi_tapdoan_bo(int id_don_vi, string ma_don_vi)
        {
            DataTable dt = SqlDataHelper.CallRetrievalStoredProcedure("MIS_don_vi_Get_donvi_tapdoan_bo",
                new SqlParameter[]{
					new SqlParameter("@id_don_vi",id_don_vi),				
                    new SqlParameter("@ma_don_vi",ma_don_vi)
					});
            return dt;
        }

        public DataTable Check_Ma_donvi(int id_don_vi, string ma_don_vi)
        {
            DataTable dt = SqlDataHelper.CallRetrievalStoredProcedure("MIS_don_vi_Check_Madonvi",
                new SqlParameter[]{
                    new SqlParameter("@id_don_vi",id_don_vi),
					new SqlParameter("@ma_don_vi",ma_don_vi)				 
					});
            return dt;
        }
        public DataTable Check_Ten_donvi(int id_don_vi, string ten_don_vi)
        {
            DataTable dt = SqlDataHelper.CallRetrievalStoredProcedure("MIS_don_vi_Check_Tendonvi",
                new SqlParameter[]{
                    new SqlParameter("@id_don_vi",id_don_vi),
					new SqlParameter("@ten_don_vi",ten_don_vi)				 
					});
            return dt;
        }
        #endregion
    }
}
